#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int r, c, roomarea, roomnum = 0, maxroom = 0;
int room[60][60], visit[60][60];
void dfs(int i, int j)
{
    if (visit[i][j])
        return;
    roomarea++;
    visit[i][j] = roomnum;
    if (!(room[i][j] & 1))
        dfs(i, j - 1);
    if (!(room[i][j] & 2))
        dfs(i - 1, j);
    if (!(room[i][j] & 4))
        dfs(i, j + 1);
    if (!(room[i][j] & 8))
        dfs(i + 1, j);
}
int main()
{
    scanf("%d %d", &r, &c);
    for (int i = 1; i <= r; i++)
    {
        for (int j = 1; j <= c; j++)
        {
            scanf("%d", &room[i][j]);
        }
    }
    memset(visit, 0, sizeof(visit));
    for (int i = 1; i <= r; i++)
    {
        for (int j = 1; j <= c; j++)
        {
            if (!visit[i][j])
            {
                roomnum++;
                roomarea = 0;
                dfs(i, j);
                maxroom = max(maxroom, roomarea);
            }
        }
    }
    cout << roomnum << endl
         << maxroom;
    return 0;
}